#include "mainwindow.h"
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{

    //初始化界面状态
    this->initUi();
    //初始化主窗口UI
    this->mainUi();

    //处理子窗口发出的关闭窗口的信号
    connect(&loginPage, &LoginWidget::closeWinSign, this, &MainWindow::dealClose);



    //处理切换窗口信号
    connect(&switchButton, &QPushButton::released, this, &MainWindow::changeWin);

    //处理子窗口信号
    void (LoginWidget::*funSignal) () =  &LoginWidget::loginSign;//重命名
    connect(&loginPage,funSignal, this, &MainWindow::dealLogin);

    //处理带参数子窗口信号
    void (LoginWidget::*funSignals)(QString) =  &LoginWidget::loginSign;//重命名
    connect(&loginPage, funSignals, this, &MainWindow::dealLogins);



}

MainWindow::~MainWindow()
{

}

//初始化界面
void MainWindow::initUi()
{

    //子窗口显示
    loginPage.show();
    //主窗口隐藏
    this->hide();
}





//显示主页面的界面
void MainWindow::mainUi()
{
    //主窗口大小
    resize(2000, 1500);
    setWindowTitle("主窗口");

    //窗口菜单
    this->menuWin();


    //切换账号按钮
    switchButton.setParent(this);
    switchButton.setText("切换账号");
    switchButton.setGeometry(100, 100, 100, 50);
}

//menu
void MainWindow::menuWin()
{
    //菜单栏
    QMenuBar *mBar = menuBar();

    //添加菜单
    QMenu *pFile = mBar->addMenu("文件");

    //添加菜单项
    QAction *pNew = pFile->addAction("新建");
}

void MainWindow::changeWin()
{
    //子窗口显示
    loginPage.show();
    //主窗口隐藏
    this->hide();
}

void MainWindow::dealLogin()
{
    //子窗口隐藏
    loginPage.hide();
    //主窗口显示
    this->show();
}


void MainWindow::dealLogins(QString token)
{
    qDebug() << token << endl;
    //子窗口隐藏
    loginPage.hide();
    //主窗口显示
    this->show();
}

void MainWindow::dealClose()
{
    qDebug() << "dealClose";
    loginPage.close();
    this->close();
}
